/**
 * @product: PCDC-CMS
 * @copyright: FSAI-南征北战信息科技
 * @filename: com.fsai.cms.controller.cms.PageController.java
 *
 * @link: Http://www.fastsai.com
 * @jdkv: Jdk 1.8
 */
package com.fsai.cms.controller.cms;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.fsai.cms.config.CmsSiteConfig;
import com.fsai.cms.domain.BaseLeader;
import com.fsai.cms.domain.BaseOrg;
import com.fsai.cms.domain.BaseSiteCfg;
import com.fsai.cms.domain.CmsCate;
import com.fsai.cms.domain.CmsCont;
import com.fsai.cms.domain.CmsEduVideo;
import com.fsai.cms.domain.PageAboutUs;
import com.fsai.cms.domain.PageCenter;
import com.fsai.cms.domain.PageCommon;
import com.fsai.cms.domain.PageRepairUpgrade;
import com.fsai.cms.service.ICmsCateService;
import com.fsai.cms.service.ICmsContService;
import com.fsai.cms.service.ICmsPubService;

import io.swagger.annotations.Api;
import springfox.documentation.annotations.ApiIgnore;

/**
 *
 * @project: pcdc-cms-web
 *
 * @author: JaffeHe
 * @email: JaffeHe@foxmail.com
 * @date: 2021-03-13 12:00
 *
 * @ChangeLog<br/>
 * 				Developer Date Comment <br/>
 */
@RestController
@RequestMapping("/page")
@Api(tags = "页面管理")
public class PageController {

	@Autowired
	private ICmsPubService cmsPubService;
	@Autowired
	private ICmsCateService cmsCateService;
	@Autowired
	private ICmsContService cmsContService;
	@Autowired
	private CmsSiteConfig siteCfg;

	@ApiIgnore
	@GetMapping("/center/{cateCode}")
	public ModelAndView pgcenter(@PathVariable("cateCode") String cateCode, Model model) {
		//0分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);

		//1中心介绍内容
		PageCenter pgCenter = cmsPubService.findPageCenter();
		model.addAttribute("pgCenter", pgCenter);
		//2中心领导列表
		String orgCode = cmsPubService.getSycConfVal("biz.deforg.code");
		List<BaseLeader> orgLeaders = cmsPubService.findOrgLeaders(orgCode);
		model.addAttribute("orgLeaders", orgLeaders);
		//3下设机构
		List<BaseOrg> subOrg = cmsPubService.findSubOrg();
		subOrg.remove(subOrg.size()-1);//20210407显示问题，特意去除最后一个机构，中国爱华影视中心
		model.addAttribute("subOrg", subOrg);

		return new ModelAndView("pcdc/pgcenter", "biz", model);
	}

	//主站通用页面
	@ApiIgnore
	@GetMapping("/comm/{cateCode}/{pgCode}")
	public ModelAndView pgcomm(@PathVariable("cateCode") String cateCode, @PathVariable("pgCode") String pgCode,
			Model model) {
		//0分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);

		//1页面信息
		PageCommon pgcomm = cmsPubService.queryPageInfoByCode(pgCode);
		model.addAttribute("pgcomm", pgcomm);

		return new ModelAndView("pcdc/pgcomm", "biz", model);
	}

	//教育首页
	@ApiIgnore
	@GetMapping("/edu/{cateCode}")
	public ModelAndView edu(@PathVariable("cateCode") String cateCode, Model model) {
		//0分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);
		//0.1工作动态子类 - 页面显示全部分页
		CmsCate subCate1 = cmsCateService.querySubCate(cmsCate.getCateId(), "工作动态");
		model.addAttribute("subCate1", subCate1);
		//0.2教育视频子类
		CmsCate subCate2 = cmsCateService.querySubCate(cmsCate.getCateId(), "教育视频");
		//0.3最新消息子类-20210414改版一套教育页面
		CmsCate subCate3 = cmsCateService.querySubCate(cmsCate.getCateId(), "最新消息");

		//1.1工作动态top信息
//		List<CmsCont> news = cmsContService.selectTopNews(subCate1.getCateId(), subCate1.getRecomPageCount());
//		model.addAttribute("news", news);

		//1.2教育视频top
		List<CmsEduVideo> topEduVideos = cmsPubService.selectTopEduVideo(subCate2.getRecomPageCount());
		model.addAttribute("topEduVideos", topEduVideos);
		
		//1.3最新消息top
		List<CmsCont> topNews = cmsContService.selectTopNews(subCate3.getCateId(), subCate3.getRecomPageCount()); 
		model.addAttribute("topNews", topNews);

		//3站点默认图片
		BaseSiteCfg siteInfo = cmsPubService.selSiteInfo(siteCfg.getMainId());
		model.addAttribute("siteInfo", siteInfo);

		return new ModelAndView("pcdc/pgedun", "biz", model);
	}

	//教育下视频页
	@ApiIgnore
	@GetMapping("/edu/video/{cateCode}")
	public ModelAndView eduVideo(@PathVariable("cateCode") String cateCode, Model model) {
		//0分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);

		return new ModelAndView("pcdc/pgeduvideo", "biz", model);
	}

	@ApiIgnore
	@GetMapping("/aboutus/{cateCode}")
	public ModelAndView aboutUs(@PathVariable("cateCode") String cateCode, Model model) {
		String orgCode = cmsPubService.getSycConfVal("biz.deforg.code");
		//1关于我们信息
		PageAboutUs aboutUs = cmsPubService.findAboutUsByOrgCode(orgCode);
		model.addAttribute("aboutUs", aboutUs);
		//2机构领导
		List<BaseLeader> orgLeaders = cmsPubService.findOrgLeaders(orgCode);
		model.addAttribute("orgLeaders", orgLeaders);

		//3分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);

		return new ModelAndView("pcdc/pgaboutus", "biz", model);
	}

	//下属机构的关于我们
	@ApiIgnore
	@GetMapping("/aboutus/{orgCode}/{cateCode}")
	public ModelAndView orgAboutUs(@PathVariable("orgCode") String orgCode, @PathVariable("cateCode") String cateCode,
			Model model) {
		model.addAttribute("orgCode", orgCode);
		//1关于我们信息
		PageAboutUs aboutUs = cmsPubService.findAboutUsByOrgCode(orgCode);
		model.addAttribute("aboutUs", aboutUs);
		//2机构领导
		List<BaseLeader> orgLeaders = cmsPubService.findOrgLeaders(orgCode);
		model.addAttribute("orgLeaders", orgLeaders);

		//3分类信息
		CmsCate cmsCate = cmsCateService.queryCateByCode(cateCode);
		model.addAttribute("cmsCate", cmsCate);

		return new ModelAndView("pcdc/subpgaboutus", "biz", model);
	}

	//维护页面
	@ApiIgnore
	@GetMapping("/repair")
	public ModelAndView repair(Model model) {
		//0w维护信息
		PageRepairUpgrade repair = cmsPubService.findRepairUpgrade();
		model.addAttribute("repair", repair);

		return new ModelAndView("pcdc/pgrepair", "biz", model);
	}

	@ApiIgnore
	@GetMapping("/vplay/{vId}")
	public ModelAndView videoPlay(@PathVariable("vId") String vId, Model model) {
		//0查询视频信息
		CmsEduVideo video = cmsPubService.findVideoById(vId);
		model.addAttribute("video", video);

		return new ModelAndView("pcdc/vplay", "biz", model);
	}

}
